package com.mym;

import java.util.ArrayList;
import java.util.List;

/**
 * @author miao
 * @version 1.0
 * @date 2025/4/18 14:25
 * @description
 */
public class Test2 {
        public static void main(String[] args) {
            // 1. 创建 List 并添加三个工人
            List<Worker> workers = new ArrayList<>();
            workers.add(new Worker("zhang3", 18, 3000));
            workers.add(new Worker("li4", 25, 3500));
            workers.add(new Worker("wang5", 22, 3200));

            // 2. 在 li4 之前插入一个工人
            workers.add(1, new Worker("zhao6", 24, 3300));

            // 3. 删除 wang5 的信息
            workers.removeIf(worker -> worker.getName().equals("wang5"));

            // 4. 利用 for 循环遍历，打印 List 中所有工人的信息，并统计和计算工人的平均工资
            int totalSalary = 0;
            for (Worker worker : workers) {
                System.out.println(worker);
                totalSalary += worker.getSalary();
            }

            double averageSalary = (double) totalSalary / workers.size();
            System.out.printf("平均工资: %.2f%n", averageSalary);
        }
    }


